<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>                  
	<meta http-equiv=Content-Type content="text/html;charset=utf-8">
	<meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
	<meta content=always name=referrer>
	<title>OpenLayers 3地图示例</title>
	<link href="../ol3.13.1/ol.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../ol3.13.1/ol.js" charset="utf-8"></script>
</head>

<body>
	<div id="map1" style="width: 40%, height: 400px"></div>
	<div id="map2" style="width: 40%, height: 400px"></div>
	<input type="button" onClick="swapMap();" value="调换地图" />
	<script>
		// 创建第一个地图
	  var map1 = new ol.Map({
			layers: [
				new ol.layer.Tile({source: new ol.source.OSM()})
			],
			view: new ol.View({
				center: [0, 0],
				zoom: 2
			}),
			target: 'map1'
	  });
		
		// 创建第二个地图
		var map2 = new ol.Map({
			layers: [
				new ol.layer.Tile({source: new ol.source.OSM()})
			],
			view: new ol.View({
				center: [0, 0],
				zoom: 2
			}),
			target: 'map2'
	  });
		
		function swapMap() {
			// 改变两个地图的容器
			map1.setTarget('map2');
			map2.setTarget('map1');
		}
	</script>
</body>
	
</html>